package com.itheima.builder;

public class Product {

    private String name;
    private Integer type;

    //私有方法的作用是防止Product直接通过构造方法创建
    private Product(Builder builder){
        this.name = builder.name;
        this.type = builder.type;
    }

    //最终通过Builder中的方法，将Builder中的属性复制到Product
    public static class Builder{

        private String name;
        private Integer type;

        //必须传递name
        public Builder(String name){
            this.name = name;
        }
        public Builder setName(String name){
            this.name = name;
            return this;
        }

        //可选参数
        public Builder setType(Integer name){
            this.type = type;
            return this;
        }

        public Product build(){
            return new Product(this);
        }
    }
}
